﻿using Dapper;
using HomagChina.Basic.CCT.Db.CCHS_Db;
using HomagChina.Basic.CCT.Db.CCT_Db;
using HomagChina.Basic.CCT.Tools;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.SqlClient;
using System.Linq;
using Telerik.Windows.Data;

namespace Proxy
{
    public class SearchInfoHandle
    {
        private CommonHandle Handle_Common;
        private string _sqlConnection = string.Empty;
        ObservableCollection<Proxy.LayerInfo> layerInfos = new ObservableCollection<Proxy.LayerInfo>();

        public SearchInfoHandle()
        {
            Handle_Common = new CommonHandle();
            _sqlConnection = Globle.ServerName == "Local"
                       ? "Data Source=shh-svdb02\\mssqlserver01;initial catalog=SHH-CELLCONTROLDB01;user id=cellcontrolsa;password=Ff!!377470377470"
                       : "Data Source=HOMAGHO-MB2MU04\\MSSQLSERVER01;Initial Catalog=HomagChina_CCHS;User ID=hgservice;Password=Homag";
        }

        /// <summary>
        /// 根据Ip查询设置
        /// </summary>
        /// <param name="Ip"></param>
        /// <returns></returns>
        public ObservableCollection<SetttingAppliancesModel> GetSettingsAppliancesInfoByIp(string Ip = "")
        {
            int i = 1;
            ObservableCollection<SetttingAppliancesModel> List_Model = new ObservableCollection<SetttingAppliancesModel>();
            List<T_MachineInfo> List_T = new List<T_MachineInfo>();
            try
            {
                using (Db_CCT Db = new Db_CCT())
                {
                    if (!string.IsNullOrWhiteSpace(Ip))
                    {
                        List_T = Db.T_MachineInfo.Where(s => s.IP.Contains(Ip)).ToList();
                    }
                    else
                    {
                        List_T = Db.T_MachineInfo.ToList();
                    }
                    foreach (var T in List_T)
                    {
                        List_Model.Add(Handle_Common.Mapper<SetttingAppliancesModel, T_MachineInfo>(
                            new SetttingAppliancesModel { Index = i++ }, T));
                    }
                    return List_Model;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        /// <summary>
        /// 根据Positioncode查询设置
        /// </summary>
        /// <param name="Ip"></param>
        /// <returns></returns>
        public ObservableCollection<PositionConfigModel> GetLibraryConfigByPositioncode(string PositionCode = "")
        {
            int i = 1;
            ObservableCollection<PositionConfigModel> List_Model = new ObservableCollection<PositionConfigModel>();
            List<T_CCHS_Position> List_T = new List<T_CCHS_Position>();
            try
            {
                using (Db_CCHS Db = new Db_CCHS())
                {
                    if (!string.IsNullOrWhiteSpace(PositionCode))
                    {
                        List_T = Db.T_CCHS_Position.Where(s => s.Positioncode.Contains(PositionCode)).ToList();
                    }
                    else
                    {
                        List_T = Db.T_CCHS_Position.ToList();
                    }
                    foreach (var T in List_T)
                    {
                        List_Model.Add(Handle_Common.Mapper<PositionConfigModel, T_CCHS_Position>(
                            new PositionConfigModel { Index = i++ }, T));
                    }
                    return List_Model;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        /// <summary>
        /// 根据查询设置
        /// </summary>
        /// <param name="Ip"></param>
        /// <returns></returns>
        public ObservableCollection<SetttingDirectionModel> GetSettingsDirectionInfoBySourcePos(string SourcePos = "")
        {
            int i = 1;
            ObservableCollection<SetttingDirectionModel> List_Model = new ObservableCollection<SetttingDirectionModel>();
            List<T_DirectionConfig> List_T = new List<T_DirectionConfig>();
            try
            {
                using (Db_CCT Db = new Db_CCT())
                {
                    if (!string.IsNullOrWhiteSpace(SourcePos))
                    {
                        List_T = Db.T_DirectionConfig.Where(s => s.SourcePos.Contains(SourcePos)).ToList();
                    }
                    else
                    {
                        List_T = Db.T_DirectionConfig.ToList();
                    }
                    foreach (var T in List_T)
                    {
                        List_Model.Add(Handle_Common.Mapper<SetttingDirectionModel, T_DirectionConfig>
                            (new SetttingDirectionModel() { Index = i++ }, T));
                    }
                    return List_Model;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        /// <summary>
        /// 根据查询设置
        /// </summary>
        /// <param name="Ip"></param>
        /// <returns></returns>
        public ObservableCollection<SetttingBasicModel> GetSettingsBasicInfoByDescribe(string Describe)
        {
            int i = 1;
            ObservableCollection<SetttingBasicModel> List_Model = new ObservableCollection<SetttingBasicModel>();
            List<T_BasicInfo> List_T = new List<T_BasicInfo>();
            try
            {
                using (Db_CCT Db = new Db_CCT())
                {
                    if (!string.IsNullOrWhiteSpace(Describe))
                    {
                        List_T = Db.T_BasicInfo.Where(s => s.Describe.Contains(Describe)).ToList();
                    }
                    else
                    {
                        List_T = Db.T_BasicInfo.ToList();
                    }
                    foreach (var T in List_T)
                    {
                        List_Model.Add(Handle_Common.Mapper<SetttingBasicModel, T_BasicInfo>
                            (new SetttingBasicModel() { Index = i++ }, T));
                    }
                    return List_Model;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        /// <summary>
        /// 获取系统版本数据
        /// </summary>
        /// <returns></returns>
        public InformationModel GetSystemInfoMation()
        {
            InformationModel InforMationModel = new InformationModel();
            try
            {
                using (Db_CCT Db = new Db_CCT())
                {
                    InformationModel model = new InformationModel();
                    T_InformationConfig modelConfig = Db.T_InformationConfig.OrderByDescending(s => s.Id).FirstOrDefault();
                    return Handle_Common.Mapper<InformationModel, HomagChina.Basic.CCT.Db.CCT_Db.T_InformationConfig>(model, modelConfig);
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        /// <summary>
        /// 获取报错信息
        /// Error or Warning
        ///
        /// </summary>
        /// <param name="Type">Error or Warning </param>
        /// <returns></returns>
        public ObservableCollection<ErrorMessageModel> GetErrorMessageMation(string Type)
        {
            //int i = 0;
            //ObservableCollection<ErrorMessageModel> List_Model = new ObservableCollection<ErrorMessageModel>();
            //List<HomagChina.Basic.CCT.Db.CCHS_Db.T_ErrorMessage> List_T = new List<HomagChina.Basic.CCT.Db.CCHS_Db.T_ErrorMessage>();
            //try
            //{
            //    using (Db_CCHS Db = new Db_CCHS())
            //    {
            //        switch (Type)
            //        {
            //            case "All":
            //                List_T = Db.T_ErrorMessage.ToList();
            //                break;

            //            case "Error":

            //                List_T = Db.T_ErrorMessage.Where(s => s.State == 0).ToList();
            //                break;

            //            case "Warning":
            //                List_T = Db.T_ErrorMessage.Where(s => s.State == 1).ToList();
            //                break;

            //            default:
            //                break;
            //        }

            //        foreach (var T in List_T)
            //        {
            //            ErrorMessageModel Model = new ErrorMessageModel();
            //            Model = Handle_Common.Mapper(Model, T);
            //            Model.Index = ++i;
            //            List_Model.Add(Model);
            //        }
            //        return List_Model;
            //   }
            //}
            //catch (Exception ex)
            //{
            return null;
            //}
        }

        /// <summary>
        /// 获取总上线生产数量
        /// </summary>
        /// <returns></returns>
        public int GetTotalBoardsCount()
        {
            try
            {
                using (Db_CCHS Db = new Db_CCHS())
                {
                    return (int)Db.T_CCHS_Stock.Where(s => s.Positioncode != "Outfeed01" && s.Positioncode != "Infeed01").Sum(s => s.ActualQuantity);
                }
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        /// <summary>
        /// 获取历史信息
        /// Error or Warning
        /// </summary>
        /// <returns></returns>
        public ObservableCollection<TransHistoryModel> GetTransHistoryMation(string Type, DateTime? ArrivalTime = null, DateTime? DepartureTime = null, string Reference = null)
        {
            int i = 0;
            ObservableCollection<TransHistoryModel> List_Model = new ObservableCollection<TransHistoryModel>();
            List<T_TransHistoryRecords> List_T = new List<T_TransHistoryRecords>();
            try
            {
                using (Db_CCT Db = new Db_CCT())
                {
                    IQueryable<T_TransHistoryRecords> query = Db.T_TransHistoryRecords;

                    if (Type != "All")
                    {
                        switch (Type)
                        {
                            case "OutFeed":
                                query = query.Where(s => s.Area.Equals("OutFeed"));
                                break;

                            case "InFeed":
                                query = query.Where(s => s.State.Equals("InFeed"));
                                break;

                            default:
                                break;
                        }
                    }

                    if (ArrivalTime.HasValue)
                    {
                        query = query.Where(s => s.ArrivalTime >= ArrivalTime.Value);
                    }
                    if (DepartureTime.HasValue)
                    {
                        query = query.Where(s => s.DepartureTime <= DepartureTime.Value);
                    }
                    if (!string.IsNullOrEmpty(Reference))
                    {
                        query = query.Where(s => s.Reference == Reference);
                    }

                    List_T = query.ToList();

                    foreach (var T in List_T)
                    {
                        TransHistoryModel Model = new TransHistoryModel();
                        Model = Handle_Common.Mapper(Model, T);
                        Model.Index = ++i;
                        List_Model.Add(Model);
                    }
                    return List_Model;
                }
            }
            catch (Exception ex)
            {
                // 错误处理代码
                return null;
            }
        }

        /// <summary>
        /// 获取Outfeed信息
        ///
        /// </summary>
        /// <returns></returns>
        public ObservableCollection<string> GetOutfeedInfo()
        {
            ObservableCollection<string> list_position = new ObservableCollection<string>();
            List<string> List_T = new List<string>();
            try
            {
                using (Db_CCHS Db = new Db_CCHS())
                {
                    List_T = Db.T_CCHS_Position.Where(s => s.Positiontype == 1).Select(s => s.Positioncode).ToList();// s.Positiontype == 0 ||
                    foreach (var T in List_T)
                    {
                        list_position.Add(T);
                    }
                    list_position.Add("Pre-stacked");
                    return list_position;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        /// <summary>
        /// 获取基本配置信息
        /// </summary>
        /// <param name="SelectedOption"></param>
        /// <returns></returns>
        public List<T_BasicInfo> GetBasicInfo()
        {
            List<T_BasicInfo> t_BasicInfos = new List<T_BasicInfo>();
            try
            {
                using (Db_CCT Db = new Db_CCT())
                {
                    t_BasicInfos = Db.T_BasicInfo.ToList();
                    return t_BasicInfos;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        /// <summary>
        /// 获取库位信息
        /// </summary>
        /// <param name="area"></param>
        /// <returns></returns>
        public ObservableCollection<StorageSpaceModel> GetStorageSpaceList()
        {
            ObservableCollection<StorageSpaceModel> List_Model = new ObservableCollection<StorageSpaceModel>();
            List<T_CCHS_StorageInfo> List_T = new List<T_CCHS_StorageInfo>();
            try
            {
                using (Db_CCHS Db = new Db_CCHS())
                {
                    List_T = Db.T_CCHS_StorageInfo.ToList();
                    foreach (var T in List_T)
                    {
                        StorageSpaceModel Model = new StorageSpaceModel();
                        Model = Handle_Common.Mapper(Model, T);
                        List_Model.Add(Model);
                    }
                    return List_Model;
                }
            }
            catch
            {
                return null;
            }
        }

        public T_CCHS_JobList GetCurrentJob()
        {
            try
            {
                using (Db_CCHS Db = new Db_CCHS())
                {
                    return Db.T_CCHS_JobList.FirstOrDefault(s => s.State != 30);
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public ObservableCollection<BoardInfoModel> GetBoardsInfo(bool IsExact, string Boardcode = "")
        {
            ObservableCollection<BoardInfoModel> list_BoardsInfoModel = new ObservableCollection<BoardInfoModel>();
            try
            {
                using (SqlConnection sqlConnection = new SqlConnection())
                {
                    sqlConnection.ConnectionString = _sqlConnection;
                    sqlConnection.Open();

                    var t = sqlConnection.Query<T_CCHS_Boardlibrary>(string.IsNullOrWhiteSpace(Boardcode) ? "Select * from T_CCHS_Boardlibrary"
                        : IsExact ? "Select * from T_CCHS_Boardlibrary where Boardcode ='" + Boardcode + "'"
                        : "Select * from T_CCHS_Boardlibrary where Boardcode like N'%" + Boardcode + "%'");
                    sqlConnection.Close();
                    foreach (var T in t)
                    {
                        BoardInfoModel Model = new BoardInfoModel();
                        switch (T.Boardtype)
                        {
                            case 0:
                                Model.Boardtype = "0-垫板";
                                break;

                            case 1:
                                Model.Boardtype = "1-原材料";
                                break;

                            case 2:
                                Model.Boardtype = "2-余料";
                                break;

                            default:
                                break;
                        }
                        Model = Handle_Common.Mapper(Model, T);
                        list_BoardsInfoModel.Add(Model);
                    }

                    return list_BoardsInfoModel;
                }
            }
            catch (Exception ex)
            {
                SerilogHandle.Logger_Search.Error(ex.Message);
                return null;
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="IsExact"></param>
        /// <param name="Boardcode"></param>
        /// <returns></returns>
        public ObservableCollection<T_CCHS_Stock> GetStocksInfo(bool IsExact, string Positioncode = "")
        {
            ObservableCollection<T_CCHS_Stock> list_StockInfoModel = new ObservableCollection<T_CCHS_Stock>();
            try
            {
                using (SqlConnection sqlConnection = new SqlConnection())
                {
                    sqlConnection.ConnectionString = _sqlConnection;
                    sqlConnection.Open();

                    var t = sqlConnection.Query<T_CCHS_Stock>(string.IsNullOrWhiteSpace(Positioncode) ? "Select * from T_CCHS_Stock"
                        : IsExact ? "Select * from T_CCHS_Stock where Positioncode =N'" + Positioncode + "'"
                        : "Select * from T_CCHS_Stock where Positioncode like N'%" + Positioncode + "%'");
                    sqlConnection.Close();
                    foreach (var T in t)
                    {
                        T_CCHS_Stock stocksInfo = new T_CCHS_Stock();
                        stocksInfo = Handle_Common.Mapper(stocksInfo, T);
                        list_StockInfoModel.Add(stocksInfo);
                    }

                    return list_StockInfoModel;
                }
            }
            catch (Exception ex)
            {
                SerilogHandle.Logger_Search.Error(ex.Message);
                return null;
            }
        }

        public ObservableCollection<JobModel> GetJobList(string JobID = "")
        {
            ObservableCollection<JobModel> List_Model = new ObservableCollection<JobModel>();
            List<T_CCHS_JobList> List_T = new List<T_CCHS_JobList>();
            try
            {
                using (Db_CCHS Db = new Db_CCHS())
                {
                    List_T.AddRange(string.IsNullOrWhiteSpace(JobID) == false ?
                        Db.T_CCHS_JobList.Where(s => s.JobId.Contains(JobID)).OrderBy(s => s.Sort == null).ToList()
                        : Db.T_CCHS_JobList.OrderBy(s => s.Sort).ToList());

                    foreach (var T in List_T)
                    {
                        if (T.State.Equals(30))
                        {
                            continue;
                        }
                        JobModel jobModel = new JobModel();
                        jobModel = Handle_Common.Mapper(jobModel, T);
                        jobModel.JobType_Name = EnumOfJobType.GetName(typeof(EnumOfJobType), jobModel.JobType);
                        jobModel.State_Name = EnumOfActive.GetName(typeof(EnumOfActive), jobModel.State);
                        List_Model.Add(jobModel);
                    }
                    return List_Model;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="List_m"></param>
        /// <returns></returns>
        public Returnstructure4Boardlibrary ChckeBoardsInfo(List<BoardInfoConstruct> List_m)
        {
            Returnstructure4Boardlibrary returnstructure4Boardlibrary = new Returnstructure4Boardlibrary()
            {
                repetitious = new List<BoardInfoConstruct>(),
                boardLibraries = new List<T_CCHS_Boardlibrary>()
            };
            try
            {
                using (var Db = new Db_CCHS())
                {
                    foreach (var item in List_m)
                    {
                        T_CCHS_Boardlibrary t = Handle_Common.Mapper(new T_CCHS_Boardlibrary(), item);
                        returnstructure4Boardlibrary.boardLibraries.Add(t);
                        if (Db.T_CCHS_Boardlibrary.FirstOrDefault(s => s.Boardcode.Equals(item.Boardcode)) != null)
                        {
                            returnstructure4Boardlibrary.repetitious.Add(item);
                        }
                    }
                }
                return returnstructure4Boardlibrary;
            }
            catch (Exception ex)
            {
                SerilogHandle.Logger_Modify.Error(ex.Message);
                returnstructure4Boardlibrary.boardLibraries = null;
                returnstructure4Boardlibrary.boardLibraries = null;
                return returnstructure4Boardlibrary;
            }
        }

        public List<string> GetMaterialList()
        {
            try
            {
                List<string> list = new List<string>();
                using (var Db = new Db_CCHS())
                {
                    return list = Db.T_CCHS_Boardlibrary.GroupBy(s => s.Material).Select(s => s.Key).ToList();
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        /// <summary>
        /// 获取库位信息
        /// </summary>
        ///
        public ObservableCollection<StockDetailModel> GetStockInfo(T_CCHS_Stock StockModel)
        {
            ObservableCollection<StockDetailModel> list_StockInfoModel = new ObservableCollection<StockDetailModel>();
            List<T_CCHS_StockDetail> List_T = new List<T_CCHS_StockDetail>();
            try
            {
                using (Db_CCHS Db = new Db_CCHS())
                {
                    List_T = Db.T_CCHS_StockDetail.Where(s => s.Positioncode.Equals(StockModel.Positioncode)).ToList();
                    var StockDetailCount = List_T.Count();
                    foreach (var T in List_T)
                    {
                        StockDetailModel stockDetailModel = new StockDetailModel();
                        stockDetailModel = Handle_Common.Mapper(stockDetailModel, T);
                        stockDetailModel.IsDeleted = stockDetailModel.Layer == StockDetailCount ? true : false;
                        list_StockInfoModel.Add(stockDetailModel);
                    }

                    return list_StockInfoModel;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="JobId"></param>
        /// <param name="StackId"></param>
        /// <returns></returns>
        public ObservableCollection<TaskInfoModel> GetTaskInfoModels(string JobId = "", string StackId = "")
        {
            ObservableCollection<TaskInfoModel> list = new ObservableCollection<TaskInfoModel>();
            try
            {
                using (Db_CCHS Db = new Db_CCHS())
                {
                    var infos = Db.T_CCHS_TaskDetail.Where(s => s.JobId.Equals(JobId) && s.StackId.Equals(StackId)).ToList();

                    foreach (var item in infos)
                    {
                        list.Add(Handle_Common.Mapper(new TaskInfoModel(), item));
                    }
                }
                foreach (var item in list)
                {
                    switch (item.BoardType)
                    {
                        case 0:
                            item.BoardType_Translate = "0-垫板";
                            break;

                        case 1:
                            item.BoardType_Translate = "1-原材料";
                            break;

                        case 2:
                            item.BoardType_Translate = "2-余料";
                            break;

                        default:
                            break;
                    }

                    switch (item.TransferState)
                    {
                        case 0:
                            item.State_Translate = "等待执行";
                            break;

                        case 1:
                            item.State_Translate = "正在执行";
                            break;

                        case 2:
                            item.State_Translate = "执行完成";
                            break;

                        case 3:
                            item.State_Translate = "任务异常";
                            break;

                        default:
                            break;
                    }

                    switch (item.Tasktype)
                    {
                        case 0:
                            item.TaskType_Translate = "入库任务";
                            break;

                        case 1:
                            item.State_Translate = "出库任务";
                            break;

                        case 2:
                            item.State_Translate = "移库任务";
                            break;

                        case 3:
                            item.State_Translate = "预叠板任务";
                            break;

                        case 4:
                            item.State_Translate = "无序叠板任务";
                            break;

                        case 5:
                            item.State_Translate = "有序叠板";
                            break;

                        case 6:
                            item.State_Translate = "垫板任务";
                            break;

                        default:
                            break;
                    }
                }
                return list;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public List<T_CCHS_Position> GetPositionInfos()
        {
            try
            {
                using (Db_CCHS Db = new Db_CCHS())
                {
                    return Db.T_CCHS_Position.ToList();
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public List<T_CCHS_Stock> GetStockInfos()
        {
            try
            {
                using (Db_CCHS Db = new Db_CCHS())
                {
                    return Db.T_CCHS_Stock.ToList();
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public List<string> GetAvailablelocations()
        {
            List<string> availablelocations = new List<string>();
            try
            {
                using (SqlConnection sqlConnection = new SqlConnection())
                {
                    sqlConnection.ConnectionString = _sqlConnection;
                    sqlConnection.Open();

                    availablelocations = sqlConnection.Query<string>("Select Positioncode from View_Position_Stock where Positiontype='2' and ActualQuantity < 108").ToList();
                    sqlConnection.Close();
                }
                return availablelocations;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public int GetUsage(string storageCode)
        {
            int totalUsage = 0;
            try
            {
                using (Db_CCHS Db = new Db_CCHS())
                {
                    T_CCHS_Stock stockInfo = Db.T_CCHS_Stock.FirstOrDefault(s => s.Positioncode.Equals(storageCode));

                    //计算百分比并取整
                    totalUsage = (int)Math.Ceiling((double)stockInfo.ActualQuantity / 60 * 100);
                }
                return totalUsage;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="Positioncode"></param>
        /// <returns></returns>
        public int GetActualQuantity(string Positioncode)
        {
            try
            {
                using (Db_CCHS Db = new Db_CCHS())
                {
                    //获取实际库存
                    var storageType = Db.T_CCHS_StorageInfo.FirstOrDefault(s => s.StorageCode.Equals(Positioncode)).Storagetype;
                    if (storageType == 6)
                    {
                        return 0;
                    }
                    //获取实际库存
                    var actualQuantity = (int)Db.T_CCHS_Stock.FirstOrDefault(s => s.Positioncode.Equals(Positioncode)).ActualQuantity;
                    return actualQuantity;
                }
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public T_CCHS_GantryPosition GetInfo()
        {
            try
            {
                using (Db_CCHS Db = new Db_CCHS())
                {
                    return Db.T_CCHS_GantryPosition.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }



        /*针对展会*/
        /// <summary>
        /// 
        /// </summary>
        /// <param name="SortCount">总仓位数</param>
        /// <param name="SortBoardCount">仓位板件数</param>
        /// <returns></returns>
        public (int, int) GetContainer()
        {
            try
            {
                var info = 机器人分拣总控.FeedManageController.GetContainerInfo();
                return (info.SortCount, info.SortBoardCount);
            }
            catch (Exception)
            {

                throw;
            }
        }

        public Batch4Storage GetBatchInfo()
        {
            try
            {
                var info = 机器人分拣总控.FeedManageController.GetBatchInfo();
                return new Batch4Storage()
                {

                    BatchNo = info.BatchNo,
                    BatchInConut = info.BatchInCount,
                    BatchOutCount = info.BatchOutCount,
                    BatchWaitCount = info.BatchWaitCount,
                    BatchPrePackNum = info.BatchPrePackNum,
                    BatchCabNum = info.BatchCabNum
                };
            }
            catch (Exception)
            {

                throw;
            }
        }


        public List<BoardInfo4Storage> GetBatchDetailInfo()
        {
            List<BoardInfo4Storage> boardsinfo = new List<BoardInfo4Storage>();
            try
            {
                var info = 机器人分拣总控.FeedManageController.ShowSortingBoards("GZZHCS", "2");
                foreach (var item in info)
                {
                    boardsinfo.Add(new BoardInfo4Storage()
                    {
                        Boardcode = item.Code,
                        RoomNo = item.RoomNo,
                        MaterialName = item.MaterialName,
                        Length = item.Length,
                        Width = item.Width,
                        Thickness = item.Height,
                        BoardState = item.BoardState.ToString(),
                        PrePackID = item.PrePackID
                    });
                }
                return boardsinfo;
            }
            catch (Exception)
            {

                throw;
            }
        }

        int infoCount = 0;
        public int GetStorageCount()
        {
            try
            {
                return 机器人分拣总控.FeedManageController.GetBoardsInContainer().Count();
            }
            catch
            {
                return 0;
            }
        }


        public ObservableCollection<Proxy.LayerInfo> GetStorageInfo()
        {
            LayerInfo layerInfo;
            layerInfos.Clear();
            try
            {
                var info = 机器人分拣总控.FeedManageController.GetBoardsInContainer();
                foreach (var item in info)
                {
                    layerInfo = new LayerInfo();
                    layerInfo.Boardcode = item.Code;
                    layerInfo.Length = item.Length;
                    layerInfo.Width = item.Width;
                    layerInfo.Thickness = item.Height;
                    layerInfo.SortState = item.BoardState.ToString();
                    layerInfo.RSShelfOrder = item.robotsort.RSShelfOrder;
                    layerInfo.RSLayerNum = item.robotsort.RSLayerNum;
                    layerInfo.RSCenterX = item.robotsort.RSCenterX - 100;
                    layerInfo.CalCenterX = item.robotsort.CalCenterX;
                    layerInfo.RSCenterY = item.robotsort.RSCenterY;
                    layerInfo.SortType = item.robotsort.SortType.ToString();
                    layerInfo.SortState = item.robotsort.SortState.ToString();
                    layerInfos.Add(layerInfo);
                }
                return layerInfos;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }
}